{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python395jvsc74a57bd0d21333ff62c43b8d3f22f2fffa3b7389f580599dfc1ab4fc74fc1532be50abca",
   "display_name": "Python 3.9.5 64-bit"
  },
  "metadata": {
   "interpreter": {
    "hash": "d21333ff62c43b8d3f22f2fffa3b7389f580599dfc1ab4fc74fc1532be50abca"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "1\n2\n2\n"
     ]
    }
   ],
   "source": [
    "# 两个 __ 开头，代表此属性为私有属性\n",
    "class JustCounter:\n",
    "    __secretCunt = 0  # 私有属性\n",
    "    publicCount = 0 #公开属性\n",
    "\n",
    "    def count(self):\n",
    "        self.__secretCunt += 1\n",
    "        self.publicCount += 1\n",
    "        print (self.__secretCunt)  # 调用私有属性\n",
    "\n",
    "counter = JustCounter()\n",
    "counter.count()\n",
    "counter.count()\n",
    "\n",
    "print ( counter.publicCount )\n",
    "print ( counter.__secretCunt ) # 报错，实例不能访问私有属性\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}